.class public Lcom/felhr/usbserial/UsbSerialDevice$ReadThread;
.super Ljava/lang/Thread;
.source "UsbSerialDevice.java"


# annotations
.annotation system Ldalvik/annotation/EnclosingClass;
    value = Lcom/felhr/usbserial/UsbSerialDevice;
.end annotation

.annotation system Ldalvik/annotation/InnerClass;
    accessFlags = 0x4
    name = "ReadThread"
.end annotation


# instance fields
.field private callback:Lcom/felhr/usbserial/UsbSerialInterface$UsbReadCallback;

.field private inEndpoint:Landroid/hardware/usb/UsbEndpoint;

.field final synthetic this$0:Lcom/felhr/usbserial/UsbSerialDevice;

.field private usbSerialDevice:Lcom/felhr/usbserial/UsbSerialDevice;

.field private working:Ljava/util/concurrent/atomic/AtomicBoolean;


# direct methods
.method public constructor <init>(Lcom/felhr/usbserial/UsbSerialDevice;Lcom/felhr/usbserial/UsbSerialDevice;)V
    .locals 0

    .line 332
    iput-object p1, p0, Lcom/felhr/usbserial/UsbSerialDevice$ReadThread;->this$0:Lcom/felhr/usbserial/UsbSerialDevice;

    invoke-direct {p0}, Ljava/lang/Thread;-><init>()V

    .line 333
    iput-object p2, p0, Lcom/felhr/usbserial/UsbSerialDevice$ReadThread;->usbSerialDevice:Lcom/felhr/usbserial/UsbSerialDevice;

    .line 334
    new-instance p1, Ljava/util/concurrent/atomic/AtomicBoolean;

    const/4 p2, 0x1

    invoke-direct {p1, p2}, Ljava/util/concurrent/atomic/AtomicBoolean;-><init>(Z)V

    iput-object p1, p0, Lcom/felhr/usbserial/UsbSerialDevice$ReadThread;->working:Ljava/util/concurrent/atomic/AtomicBoolean;

    return-void
.end method

.method private onReceivedData([B)V
    .locals 1

    .line 391
    iget-object v0, p0, Lcom/felhr/usbserial/UsbSerialDevice$ReadThread;->callback:Lcom/felhr/usbserial/UsbSerialInterface$UsbReadCallback;

    if-eqz v0, :cond_0

    .line 392
    invoke-interface {v0, p1}, Lcom/felhr/usbserial/UsbSerialInterface$UsbReadCallback;->onReceivedData([B)V

    :cond_0
    return-void
.end method


# virtual methods
.method public run()V
    .locals 5

    .line 347
    :cond_0
    :goto_0
    iget-object v0, p0, Lcom/felhr/usbserial/UsbSerialDevice$ReadThread;->working:Ljava/util/concurrent/atomic/AtomicBoolean;

    invoke-virtual {v0}, Ljava/util/concurrent/atomic/AtomicBoolean;->get()Z

    move-result v0

    if-eqz v0, :cond_3

    .line 350
    iget-object v0, p0, Lcom/felhr/usbserial/UsbSerialDevice$ReadThread;->inEndpoint:Landroid/hardware/usb/UsbEndpoint;

    const/4 v1, 0x0

    if-eqz v0, :cond_1

    .line 351
    iget-object v2, p0, Lcom/felhr/usbserial/UsbSerialDevice$ReadThread;->this$0:Lcom/felhr/usbserial/UsbSerialDevice;

    iget-object v3, v2, Lcom/felhr/usbserial/UsbSerialDevice;->connection:Landroid/hardware/usb/UsbDeviceConnection;

    iget-object v2, v2, Lcom/felhr/usbserial/UsbSerialDevice;->serialBuffer:Lcom/felhr/usbserial/SerialBuffer;

    invoke-virtual {v2}, Lcom/felhr/usbserial/SerialBuffer;->getBufferCompatible()[B

    move-result-object v2

    const/16 v4, 0x4000

    invoke-virtual {v3, v0, v2, v4, v1}, Landroid/hardware/usb/UsbDeviceConnection;->bulkTransfer(Landroid/hardware/usb/UsbEndpoint;[BII)I

    move-result v1

    :cond_1
    if-lez v1, :cond_0

    .line 358
    iget-object v0, p0, Lcom/felhr/usbserial/UsbSerialDevice$ReadThread;->this$0:Lcom/felhr/usbserial/UsbSerialDevice;

    iget-object v0, v0, Lcom/felhr/usbserial/UsbSerialDevice;->serialBuffer:Lcom/felhr/usbserial/SerialBuffer;

    invoke-virtual {v0, v1}, Lcom/felhr/usbserial/SerialBuffer;->getDataReceivedCompatible(I)[B

    move-result-object v0

    .line 362
    iget-object v1, p0, Lcom/felhr/usbserial/UsbSerialDevice$ReadThread;->this$0:Lcom/felhr/usbserial/UsbSerialDevice;

    invoke-static {v1}, Lcom/felhr/usbserial/UsbSerialDevice;->access$000(Lcom/felhr/usbserial/UsbSerialDevice;)Z

    move-result v1

    if-eqz v1, :cond_2

    .line 364
    iget-object v1, p0, Lcom/felhr/usbserial/UsbSerialDevice$ReadThread;->usbSerialDevice:Lcom/felhr/usbserial/UsbSerialDevice;

    check-cast v1, Lcom/felhr/usbserial/FTDISerialDevice;

    iget-object v1, v1, Lcom/felhr/usbserial/FTDISerialDevice;->ftdiUtilities:Lcom/felhr/usbserial/FTDISerialDevice$FTDIUtilities;

    invoke-virtual {v1, v0}, Lcom/felhr/usbserial/FTDISerialDevice$FTDIUtilities;->checkModemStatus([B)V

    .line 366
    array-length v1, v0

    const/4 v2, 0x2

    if-le v1, v2, :cond_0

    .line 368
    iget-object v1, p0, Lcom/felhr/usbserial/UsbSerialDevice$ReadThread;->usbSerialDevice:Lcom/felhr/usbserial/UsbSerialDevice;

    check-cast v1, Lcom/felhr/usbserial/FTDISerialDevice;

    iget-object v1, v1, Lcom/felhr/usbserial/FTDISerialDevice;->ftdiUtilities:Lcom/felhr/usbserial/FTDISerialDevice$FTDIUtilities;

    invoke-virtual {v1, v0}, Lcom/felhr/usbserial/FTDISerialDevice$FTDIUtilities;->adaptArray([B)[B

    move-result-object v0

    .line 369
    invoke-direct {p0, v0}, Lcom/felhr/usbserial/UsbSerialDevice$ReadThread;->onReceivedData([B)V

    goto :goto_0

    .line 373
    :cond_2
    invoke-direct {p0, v0}, Lcom/felhr/usbserial/UsbSerialDevice$ReadThread;->onReceivedData([B)V

    goto :goto_0

    :cond_3
    return-void
.end method

.method public setCallback(Lcom/felhr/usbserial/UsbSerialInterface$UsbReadCallback;)V
    .locals 0

    .line 339
    iput-object p1, p0, Lcom/felhr/usbserial/UsbSerialDevice$ReadThread;->callback:Lcom/felhr/usbserial/UsbSerialInterface$UsbReadCallback;

    return-void
.end method

.method public setUsbEndpoint(Landroid/hardware/usb/UsbEndpoint;)V
    .locals 0

    .line 381
    iput-object p1, p0, Lcom/felhr/usbserial/UsbSerialDevice$ReadThread;->inEndpoint:Landroid/hardware/usb/UsbEndpoint;

    return-void
.end method

.method public stopReadThread()V
    .locals 2

    .line 386
    iget-object v0, p0, Lcom/felhr/usbserial/UsbSerialDevice$ReadThread;->working:Ljava/util/concurrent/atomic/AtomicBoolean;

    const/4 v1, 0x0

    invoke-virtual {v0, v1}, Ljava/util/concurrent/atomic/AtomicBoolean;->set(Z)V

    return-void
.end method
